﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCWeb.Models; // this is required...

namespace MVCWeb.Controllers
{
    public class StudentController : Controller
    {
        //
        // GET: /Student/

        public string AjaxTest() 
        { 
          return "Some random text"; 
        } 

        public ActionResult Index()
        {
          List<PLStudent> list = StudentClientService.GetStudentList();
          return View("StudentList", list);
        }

        //
        // GET: /Student/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Student/Create

        public ActionResult Create()
        {
          PLStudent student = new PLStudent();
          return View("CreateStudent", student);
        } 

        //
        // POST: /Student/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
              PLStudent student = new PLStudent();
              student.ID = collection["ID"];
              student.FirstName = collection["FirstName"];
              student.LastName = collection["LastName"];
              student.SSN = collection["SSN"];
              student.EmailAddress = collection["EmailAddress"];
              StudentClientService.CreateStudent(student);
              return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Student/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Student/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Student/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Student/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }


    }
}
